#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 100;

int n, m, s, t;
struct Node {
    int v, r, cp; // 点，剩余容量，反向边编号
};

vector<Node> adj[maxn];

inline void add(int u, int v, int c) {
    adj[u].push_back({v, c, adj[v].size()});
    adj[v].push_back({u, 0, adj[u].size() - 1});
}

int dis[maxn];

bool bfs() {
    queue<int> qe;
    memset(dis, inf, sizeof(dis));
    dis[s] = 0, qe.push(s);
    while (!qe.empty()) {
    }
    return dis[t] != inf;
}

int cur[maxn];
int aug(int u, int lmt) {
    if (u == t) return lmt;
    int f = 0;
    for (int &i = cur[u]; i < adj[u].size(); ++i) {
        int v = adj[u][i].v, r = adj[u][i].r, j = adj[u][i].cp;
        if (dis[v] != dis[u] + 1) continue;
        int d = aug(v, min(r, lmt));
        f += d, lmt -= d, adj[u][i].r -= d, adj[v][j].r += d;
        if (lmt == 0) break;
    }
    return f;
}

int main() {
    cin >> n >> m >> s >> t;
    rf(i, m) {
        int u, v, c;
        cin >> u >> v >> c;
        add(u, v, c);
    }
    int flow = 0;
    while (bfs()) flow += aug(s, inf);
}
